package com.tanhua.manage.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanhua.manage.mapper.AdminRoleMapper;
import com.tanhua.manage.pojo.AdminRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class AdminRoleService extends ServiceImpl<AdminRoleMapper, AdminRole> {

    /**
     * 获取角色信息分页数据
     *
     * @param page     当前页码
     * @param pageSize 页尺寸
     * @param name     用户名
     * @return 角色信息分页数据
     */
    public IPage<AdminRole> findInfoByPage(Integer page, Integer pageSize, String name) {

        Page<AdminRole> infoPage = new Page<>(page, pageSize);

        LambdaQueryWrapper<AdminRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotEmpty(name)) {
            lambdaQueryWrapper.like(AdminRole::getName, name);
        }
        return super.getBaseMapper().selectPage(infoPage, lambdaQueryWrapper);
    }

    public AdminRole updateById(Long id, String name, String descs,Integer state) {

        AdminRole adminRole = new AdminRole();
        adminRole.setId(id);
        adminRole.setName(name);
        adminRole.setDescs(descs);
        adminRole.setState(state);
        super.baseMapper.updateById(adminRole);
        return adminRole;
    }

    public void deleteById(Long id) {
        super.baseMapper.deleteById(id);
    }
}
